﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;

namespace WebUI.Areas.Admin.Controllers
{
    public class CommonController : Controller
    {
        //
        // GET: /Admin/Common/

        public String SaveImage()
        {
            if (Request.Files.Count != 0)
            {
                var file = Request.Files[0];
                var path = AppDomain.CurrentDomain.BaseDirectory + @"\upload\image\" + DateTime.Now.ToString("yyyyMMdd");
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);
                var newFileName = DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(file.FileName);
                try
                {
                    file.SaveAs(path + @"\" + newFileName);
                    return newFileName;
                }
                catch (Exception)
                {
                    return "error";
                }

            }
            return "error";
        }

    }
}
